package com.storage.web.controller.system;

import com.storage.common.annotation.Log;
import com.storage.common.core.controller.BaseController;
import com.storage.common.core.domain.AjaxResult;
import com.storage.common.core.domain.ServiceResponse;
import com.storage.common.core.page.TableDataInfo;
import com.storage.common.enums.BusinessType;
import com.storage.framework.web.OperationContext;
import com.storage.framework.web.enums.RequestOperation;
import com.storage.system.domain.StorageBrand;
import com.storage.system.service.IStorageBrandService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 品牌 信息操作处理
 *
 * @author storage
 * @date 2019-08-18
 */
@Api(tags = "品牌相关接口")
@RestController
public class StorageBrandController extends BaseController {

    @Autowired
    private IStorageBrandService storageBrandService;

    /**
     * 查询品牌列表
     */
    @ApiOperation(value = "查询品牌列表", notes = "查询品牌列表")
    @GetMapping("/system/storageBrand/list")
    @ResponseBody
    public TableDataInfo list(@RequestOperation OperationContext context,
                              StorageBrand storageBrand, Integer pageNum, Integer pageSize) {
        ServiceResponse<TableDataInfo> response = storageBrandService.selectStorageBrandList(context.getStorageUser(), storageBrand, pageNum, pageSize);
        return response.getData();
    }


    /**
     * 新增保存品牌
     */
    @ApiOperation(value = "新增保存品牌", notes = "新增保存品牌")
    @Log(title = "品牌", businessType = BusinessType.INSERT)
    @PostMapping("/system/storageBrand/add")
    @ResponseBody
    public AjaxResult addSave(@RequestOperation OperationContext context,
                              @RequestBody StorageBrand storageBrand) {
        return storageBrandService.insertStorageBrand(context.getStorageUser(), storageBrand);
    }

    /**
     * 修改保存品牌
     */
    @ApiOperation(value = "修改保存品牌", notes = "修改保存品牌")
    @Log(title = "品牌", businessType = BusinessType.UPDATE)
    @PostMapping("/system/storageBrand/edit")
    @ResponseBody
    public AjaxResult editSave(@RequestOperation OperationContext context,
                               @RequestBody StorageBrand storageBrand) {
        return storageBrandService.updateStorageBrand(context.getStorageUser(), storageBrand);
    }

    /**
     * 删除品牌
     */
    @ApiOperation(value = "删除品牌", notes = "删除品牌")
    @Log(title = "品牌", businessType = BusinessType.DELETE)
    @GetMapping("/system/storageBrand/remove")
    @ResponseBody
    public AjaxResult remove(@RequestParam("ids") String ids) {
        return toAjax(storageBrandService.deleteStorageBrandByIds(ids));
    }

}
